/**
 * Ajax 请求类
 * @author WYZ
 * @create 2018-02-01 15:58
 * @desc
 **/
var sajax = function () {
    var SFC_TOKEN;
    var baseUrl = "http://localhost:8080/sichuansfc/";
    /**
     * 设置token
     * @param token
     * @returns {*}
     */
    this.setToken = function (token) {
        SFC_TOKEN = token;
        return this;
    }
    /**
     *  get 请求
     * @param url
     * @param param
     */
    this.get = function (url, param) {
        if (param) {
            url += "?1=1";
            for (var key in param) {
                url += "&" + key + "=" + param[key];
            }
        }
        sfcAjax(url
            , "GET"
            , null
        );
    };
    /**
     *  post 请求
     * @param url
     * @param newParam
     */
    this.post = function (url, param) {
        sfcAjax(url
            , "POST"
            , JSON.stringify(param)
        );

    };

    function sfcAjax(url, method, params) {
        if (!url) {
            return false;
        }
        $.ajax({
            type: method,
            url: baseUrl + url,
            data: params,
            dataType: "json",
            success: function (data) {
                if (data.status == 100000) {
                    console.log(data['data'])
                    return data['data'];
                } else {
                    alert(data.msg);
                }
            },
            error: function (data) {
                alert(data.msg);
            }
        });
    }

    return this;
}();